(function () {
    var dizhi = document.getElementById('dizhi');

    dizhi.onmouseover = function () {
        this.children[1].style.backgroundPosition = '-13px 0'
    }
    dizhi.onmouseout = function () {
        this.children[1].style.backgroundPosition = '0 0'
        
    }


    // 添加城市
    var nc_ul = document.getElementById('nc_ul');
    var strAscll = ['ABCDE','FGHIJ','KLMNO','PQRST','UVWXYZ']
    for (let i = 0; i<5; i++) {
        var li = document.createElement('li');

        li.innerHTML = strAscll[i];
        li.className = 'left'
        li.setAttribute('index', i);
        nc_ul.firstElementChild.appendChild(li);
    }
    nc_ul.firstElementChild.children[0].classList.add('city_style');
    nc_ul.firstElementChild.onmouseover = function (e) {
        if (e.target.nodeName === 'LI') {
            for (let i = 0; i < nc_ul.firstElementChild.children.length; i++) {
                nc_wenzi.children[i].style.display = 'none';
                nc_ul.firstElementChild.children[i].classList.remove('city_style');
            }
            e.target.classList.add('city_style');
            nc_wenzi.children[e.target.getAttribute('index')].style.display = 'block';
        }
    }

    var nc_wenzi = document.getElementById('nc_wenzi');

    for (let i = 1; i < nc_wenzi.children.length; i++) {
        
        nc_wenzi.children[i].style.display = 'none';
    }

    var city_dong = document.getElementById('city_dong')
    var city_jing = document.getElementById('city_jing')
    var peisong_city = document.getElementById('peisong_city')
    var data = city();
    city_jing.onclick = function (e) {
        if (e.target.nodeName === 'A') {
            let obj = e.target;
            var res = data.find(item => {
                return item.label === obj.innerHTML
            })
            if (res) {
                res = res.children;
                city_dong.innerHTML = '';
                cityAppend(res, city_dong,obj.innerHTML);
                return
            }
            // 最后3个没有市
            for (let i = 0; i < data.length-3; i++) {
                res = data[i].children.find(item => {
                    return item.label === obj.innerHTML
                })
                if (res) {
                    res = res.children;
                    city_dong.innerHTML = '';
                    cityAppend(res, city_dong,obj.innerHTML);
                    return
                }
            }

            // 是 县级市 直接插入 就1个
            // var a = document.createElement('a');
            // a.innerHTML = obj.innerHTML
            // a.href = 'javascript:;'
            // city_dong.appendChild(a);
            cityAppend([{label:obj.innerHTML}], city_dong,obj.innerHTML);

            
        }
    }

    function cityAppend(data, cityHtml, text) {
        cityHtml.innerHTML=''
        data.forEach(item => {
            var a = document.createElement('a');
            a.innerHTML = item.label
            a.href = 'javascript:;'
            
            cityHtml.appendChild(a);
        });
        cityHtml.onclick = function () {
            peisong_city.innerHTML = text ||'aa'
        }
    }

    var log521 = document.getElementsByClassName('log')[1];
    window.addEventListener('scroll', function () {
        if (this.document.documentElement.scrollTop > 91) {
            log521.style.display = 'block'
        }
        else {
            log521.style.display = 'none'
            
        }
    })

})();